package com.yunxin.core.infra.persistence.repository.product;

import com.yunxin.core.domain.model.product.ProductAdvanceChargeRecord;
import com.yunxin.core.domain.model.product.ProductAdvanceChargeRecordRepository;
import com.yunxin.core.infra.persistence.converter.ProductConverter;
import com.yunxin.core.infra.persistence.entity.product.ProductAdvanceChargeRecordDO;
import com.yunxin.core.infra.persistence.mapper.product.ProductAdvanceChargeRecordExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-12-16
 */
@Repository
@RequiredArgsConstructor
public class ProductAdvanceChargeRecordRepositoryImpl implements ProductAdvanceChargeRecordRepository {

    private final ProductConverter productConverter;

    private final ProductAdvanceChargeRecordExtendMapper productAdvanceChargeRecordExtendMapper;

    @Override
    public boolean saveProductAdvanceChargeRecord(ProductAdvanceChargeRecord productAdvanceChargeRecord) {
        ProductAdvanceChargeRecordDO productAdvanceChargeRecordDO = productConverter.formProductAdvanceChargeRecord(productAdvanceChargeRecord);
        int result = productAdvanceChargeRecordExtendMapper.insertSelective(productAdvanceChargeRecordDO);
        return result > 0;
    }

    @Override
    public boolean updateProductAdvanceChargeRecord(ProductAdvanceChargeRecord productAdvanceChargeRecord) {
        ProductAdvanceChargeRecordDO productAdvanceChargeRecordDO = productConverter.formProductAdvanceChargeRecord(productAdvanceChargeRecord);
        int result = productAdvanceChargeRecordExtendMapper.updateByPrimaryKeySelective(productAdvanceChargeRecordDO);
        return result > 0;
    }

    @Override
    public ProductAdvanceChargeRecord getProductAdvanceChargeRecordById(Long id) {
        ProductAdvanceChargeRecordDO productAdvanceChargeRecordDO = productAdvanceChargeRecordExtendMapper.selectByPrimaryKey(id);
        return productConverter.toProductAdvanceChargeRecord(productAdvanceChargeRecordDO);
    }
}
